import Mock from 'mockjs'
import {param2Obj} from '@/utils'

const List = [],
  count = 100,
  BankList = [],
  tradeList = [],
  lockList = [],
  platformBalance = [
    {props: 'account', label: '主账户余额', value: 1000},
    {props: 'mg', label: 'MG', value: 100},
    {props: 'sb', label: '沙巴体育', value: 100},
    {props: 'gd', label: 'GD真人', value: 100},
    {props: 'bbin', label: 'BBIN', value: 10000},
    {props: 'im', label: 'IM体育', value: 100000},
    {props: 'nt', label: 'NT电子', value: 10000},
    {props: 'kg', label: 'KG彩票', value: 100000},
    {props: 'sy', label: '双鱼彩票', value: 10000000},
    {props: 'ag', label: 'AG', value: 100000000},
    {props: 'sl', label: '沙龙', value: 1000000000},
  ],

  financeList = [
    {props: 'name', label: '存款次数', value: 1},
    {props: 'status', label: '存款金额', value: 100},
    {props: 'proxy', label: '取款次数', value: 100},
    {props: 'phone', label: '取款金额', value: 100},
    {props: 'email', label: '手续费', value: 100},
    {props: 'birthday', label: '返水', value: 100},
    {props: 'sex', label: '红利', value: 100},
    {props: 'address', label: '存款优惠', value: 100},
    {props: 'register', label: '总投注', value: 100},
    {props: 'ip', label: '总派彩', value: 100},
    {props: 'last_login', label: '有效投注额', value: 100},
    {props: 'win_lose', label: '公司输赢', value: 100},
  ];


for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment(1, 100)',
    account: '@first',
    register_time: '@datetime()',
    login_time: +Mock.Random.date('T'),
    time: +Mock.Random.date('T'),
    register_ip: Mock.Random.ip(),
    login_ip: Mock.Random.ip(),
    ip: Mock.Random.ip(),
    domain: Mock.mock('@domain'),
    ip_address: Mock.Random.ctitle(20),
    name: '@first',
    nickname: '@first',
    deposit_times: '@integer(10, 30)',
    deposit_total: '@integer(1000, 30000)',
    withdraw_times: '@integer(10, 30)',
    withdraw_total: '@integer(1000, 30000)',
    bet_total: '@integer(1000, 30000)',
    comment: Mock.Random.ctitle(20),
    proxy: '@float(0, 100, 2, 2)',
    level: '@integer(1, 3)',
    balance: '@float(60, 100, 1)',
    money_stream: '@float(60, 100, 1)',
    operator: '@first',
    content: Mock.Random.ctitle(20),
    operatorType: Mock.Random.ctitle(5),
    // 'type|1': ['CN', 'US', 'JP', 'EU'],
    'status|1': _.map(consts.MEMBER_STATUS, 'value'),
    'device|1': _.map(consts.DEVICE_TYPE, 'value'),
  }));
  lockList.push(Mock.mock({
    id: '@increment(1, 100)',
    account: '@first',
    lockBy: '@first',
    balance: '@float(60, 100, 1)',
    lockTime: +Mock.Random.date('T'),
    lockReason: '@float(60, 100, 1)',
    // 'type|1': ['CN', 'US', 'JP', 'EU'],
    'type|1': _.map(consts.ACCOUNT_TYPE, 'value'),
    'lockLimit|1': _.map(consts.LOCK_LIMIT, 'value'),
    'lockType|1': _.map(consts.LOCK_TYPE, 'value'),
    'device|1': _.map(consts.DEVICE_TYPE, 'value'),
  }));

  tradeList.push(Mock.mock({
    id: '@increment(1, 100)',
    type: '@first',
    fee: '@datetime()',
    time: +Mock.Random.date('T'),
    money: Mock.Random.ip(),
    comment: '',
    edit_type: Mock.Random.ctitle(20),
    'type|1': ['CN', 'US', 'JP', 'EU'],
  }));

  BankList.push(Mock.mock({
    id: '@increment(1, 100)',
    bind_time: '@datetime()',
    account: '@first',
    bank_code: Mock.mock('@float(0)'),
    'bank_name|1': ['中国银行', '工商银行', '建设银行', '招商银行'],
    del_time: '@datetime()',
    member_id: Mock.mock('@natural(1, 100)'),
    cardno: Mock.mock('@float(0)'),
    'name|1': ['中国银行', '工商银行', '建设银行', '招商银行'],
    bank_deposit: Mock.Random.ctitle(20),
    // 'type|1': ['CN', 'US', 'JP', 'EU'],
    'status|1': _.map(consts.MEMBER_STATUS, 'value'),
  }))
}


export default {
  [api.MEMBER_LIST]: config => {
    const {register_time, ids, user, region, money, status, level, keywords, scope, page = 1, limit = 20} = param2Obj(config.body)

    const idsArr = ids && ids.split(',') || [];
    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      if (status && Number(item.status) !== Number(status)) return false;
      if (level && Number(item.level) !== Number(level)) return false;
      if (!_.isUndefined(ids) && idsArr.indexOf(item.name) === -1) return false
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        items: pageList
      },
      code: 1,
    };
  },

  [api.MEMBER_DETAIL]: config => {
    const {member_id} = param2Obj(config.body)

    let memberDetail = _.find(List, function (o) {
      return o.id == member_id;
    });

    if(_.isUndefined(memberDetail)){
      memberDetail = List[0]
    }

    return {
      data: {
        memberDetail: memberDetail
      },
      code: 1
    }

  },

  [api.MEMBER_BANK_LIST]: config => {
    const {member_id, page = 1, limit = 20} = param2Obj(config.body)

    let mockList = BankList.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      if (Number(item.member_id) !== Number(member_id)) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };

  },
  [api.MEMBER_UPDATE_INFO]: config => {
    const {id, name, mobile, email, birthday, address} = param2Obj(config.body)

    _.map(List, o => {
      if (Number(id) === Number(o.id)) {
        if (name) {
          o.name = name
        }
        if (mobile) {
          o.mobile = mobile
        }
        if (email) {
          o.email = email
        }
        if (birthday) {
          o.birthday = moment(birthday)
        }
        if (address) {
          o.address = address
        }
      }
    })

    return {
      data: {
        msg: '修改信息提交成功'
      },
      code: 1
    }

  },
  [api.MEMBER_UPDATE_AGENCY]: config => {
    const {member_id, agency_id} = param2Obj(config.body)

    _.map(List, o => {
      if (Number(member_id) === o.id) {
        o.proxy = agency_id
      }
    })

    return {
      data: {
        msg: '更换代理提交成功'
      },
      code: 1
    }

  },
  [api.MEMBER_UPDATE_PASS]: config => {
    console.log(config)

    return {
      data: {
        msg: '修改密码提交成功'
      },
      code: 1
    }

  },
  [api.MEMBER_BANK_EDIT]: config => {
    const {member_id, id, cardno} = param2Obj(config.body)

    _.map(BankList, o => {
      if (member_id == o.member_id && id == o.id) {
        o.cardno = cardno
      }
    });

    return {
      data: {
        msg: '银行卡修改成功'
      },
      code: 1
    }

  },
  [api.MEMBER_BANK_DEL]: config => {
    const {member_id, id} = param2Obj(config.body)

    _.map(BankList, (o, index) => {
      if (o && Number(member_id) === Number(o.member_id) && Number(id) === Number(o.id)) {
        BankList.splice(index, 1)
      }
    })

    return {
      data: {
        msg: '银行卡修改成功'
      },
      code: 1
    }

  },
  [api.MEMBER_ADD_COMMENT]: config => {
    const {id, comment} = param2Obj(config.body)

    return {
      data: {
        msg: '银行卡修改成功'
      },
      code: 1
    }

  },
  [api.MEMBER_SET_STATUS]: config => {
    return {
      data: {
        msg: '操作成功'
      },
      code: 1,
    };
  },
  [api.MEMBER_BALANCE]: config => {
    const {member_id} = param2Obj(config.body)
    const platformBalance = [{
      account: 1000 ,
      mg:100,
      sb: 100,
      sy: 10000000,
      ag: 10000000,
    }]

    return {
      data: {
        list: platformBalance
      },
      code: 1,
    };
  },
  [api.MEMBER_SYNC_BALANCE]: config => {
    const {member_id} = param2Obj(config.body)
    const platformBalance = [{
      account: 1000 ,
      mg:100,
      sb: 100,
      sy: 10000000,
      ag: 10000000,
    }]

    return {
      data: {
        list: platformBalance
      },
      code: 1,
    };
  },
  [api.MEMBER_FINANCE]: config => {
    const {trade_type, search_date} = param2Obj(config.body)

    return {
      data: {
        list: financeList,
      },
      code: 1,
    };
  },
  [api.MEMBER_TRADE_LIST]: config => {
    const {trade_type, search_date, page = 1, limit = 20} = param2Obj(config.body)
    const tradeTotal = {
      current: [
        {prop: 'deposit', label: '存款', value: '300.00'},
        {prop: 'withdrawal', label: '取款', value: '300.00'},
        {prop: 'bonus', label: '红利', value: '300.00'},
        {prop: 'rebate', label: '返水', value: '300.00'},
        {prop: 'transfer', label: '转账', value: '300.00'},
        {prop: 'fee', label: '手续费', value: '300.00'},
        {prop: 'adjustment_add', label: '资金调整-加币', value: '300.00'},
        {prop: 'adjustment_reduce', label: '资金调整-减币', value: '300.00'},
      ],
      all: [
        {prop: 'deposit', label: '存款', value: '300.00'},
        {prop: 'withdrawal', label: '取款', value: '300.00'},
        {prop: 'bonus', label: '红利', value: '300.00'},
        {prop: 'rebate', label: '返水', value: '300.00'},
        {prop: 'transfer', label: '转账', value: '300.00'},
        {prop: 'fee', label: '手续费', value: '300.00'},
        {prop: 'adjustment_add', label: '资金调整-加币', value: '300.00'},
        {prop: 'adjustment_reduce', label: '资金调整-减币', value: '300.00'},
      ]
    };

    let mockList = tradeList.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }


    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));
    return {
      data: {
        total: mockList.length,
        list: pageList,
        tradeTotal: tradeTotal
      },
      code: 1,
    };

  },
  [api.MEMBER_BALANCE_TRANSFER]: config => {
    const {toPlatform} = param2Obj(config.body)

    let _list = _.map(platformBalance, o => {
      // 回收
      if (toPlatform === 'account' && o.props !== 'account') {
        platformBalance[0].value += o.value
        o.value = 0
      } else if (o.props === toPlatform) {
        // 从中心钱包转入
        o.value += platformBalance[0].value
        platformBalance[0].value = 0
      }
      return o
    })

    return {
      data: {
        list: _list,
        msg: '转账成功'
      },
      code: 1,
    };
  },
  [api.MEMBER_OPERATOR_LOGS]: config => {
    const {member_id, limit = 20, page = 1} = param2Obj(config.body)
    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.MEMBER_LOGIN_LOGS]: config => {
    const {member_id, limit = 20, page = 1} = param2Obj(config.body)
    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.MEMBER_ARBITRAGE]: config => {
    const {member_id, limit = 20, page = 1} = param2Obj(config.body)
    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.MEMBER_OPERATE_LOGS]: config => {
    const {member_id, limit = 20, page = 1} = param2Obj(config.body)
    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.MEMBER_LOCK_LOGS]: config => {
    const {limit = 20, page = 1} = param2Obj(config.body)
    let mockList = lockList.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.MEMBER_REPEAT_IPS]: config => {
    const {member_id, limit = 20, page = 1} = param2Obj(config.body)
    let mockList = List.filter(item => {
      // if (importance && item.importance !== +importance) return false;
      // if (title && item.title.indexOf(title) < 0) return false;
      return true;
    })

    // if (sort === '-id') {
    //   mockList = mockList.reverse();
    // }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1));

    return {
      data: {
        total: mockList.length,
        list: pageList
      },
      code: 1,
    };
  },
  [api.MEMBER_LEVEL_LIST]: config => {
    const list = [
      {title: '兜底层', value: 1},
      {title: '新用户', value: 2},
      {title: '大额用户', value: 3},
    ];

    return {
      data: {
        list: list
      },
      code: 1,
    };
  },
  [api.MEMBER_RUNNING_WATER_DETAIL]: config => {
    return  {
      "code":1,
      "data":{
        "endRow":0,
        "firstPage":0,
        "hasNextPage":false,
        "hasPreviousPage":false,
        "isFirstPage":true,
        "isLastPage":true,
        "lastPage":0,
        "list":[   {
          "createTime": "1553069667017",
          "orderId": "ABCDEFG123456789",
          "type": "1(临时值)",
          "amount": "100",
          "magnificationFactor": "1",
          "singleBettingDesire": "100",
          "totalBettingDesire": "100",
          "leftBettingDesireBefore": "100",
          "leftBettingDesireAfter": "100",
          "operator": "admin",
          "status": "1",
          "remark": "我是备注信息"
        }, {
          "createTime": "1553069667017",
          "orderId": "ABCDEFG123456789",
          "type": "1(临时值)",
          "amount": "100",
          "magnificationFactor": "1",
          "singleBettingDesire": "100",
          "totalBettingDesire": "100",
          "leftBettingDesireBefore": "100",
          "leftBettingDesireAfter": "100",
          "operator": "admin",
          "status": "1",
          "remark": "我是备注信息"
        }, {
          "createTime": "1553069667017",
          "orderId": "ABCDEFG123456789",
          "type": "1(临时值)",
          "amount": "100",
          "magnificationFactor": "1",
          "singleBettingDesire": "100",
          "totalBettingDesire": "100",
          "leftBettingDesireBefore": "100",
          "leftBettingDesireAfter": "100",
          "operator": "admin",
          "status": "1",
          "remark": "我是备注信息"
        }],
        "navigateFirstPage":0,
        "navigateLastPage":0,
        "navigatePages":8,
        "navigatepageNums":[],
        "nextPage":0,
        "pageNum":1,
        "pageSize":0,
        "pages":0,
        "prePage":0,
        "size":0,
        "startRow":0,
        "total":0
    },
      "message":"SUCCESS"
    }
  },
}
